package com.yjc.drygoods.ware.exception;

import com.yjc.common.exception.BizCodeEnume;
import com.yjc.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author yjc
 * @create 2022-11-04 14:45
 */
@Slf4j
@RestControllerAdvice(basePackages = {"com.yjc.drygoods.ware"})
public class WareExceptionControllerAdvice {

    @ExceptionHandler(value = NotClearStockException.class)
    public R NotClearStockException(NotClearStockException e) {
        log.error("异常信息：{}，异常类型：{}", e.getMessage(), e.getClass());
        return R.error(BizCodeEnume.NOT_CLEAR_STOCK.getCodeException(), BizCodeEnume.NOT_CLEAR_STOCK.getMessageException());
    }

    @ExceptionHandler(value = PurchaseNumException.class)
    public R PurchaseNumException(PurchaseNumException e) {
        log.error("异常信息：{}，异常类型：{}", e.getMessage(), e.getClass());
        return R.error(BizCodeEnume.PURCHASE_NUM_EXCEPTION.getCodeException(), BizCodeEnume.PURCHASE_NUM_EXCEPTION.getMessageException() + "\t" + e.getMessage());
    }

    @ExceptionHandler(value = NotExitStockException.class)
    public R NotExitStockException(NotExitStockException e) {
        log.error("异常信息：{}，异常类型：{}", e.getMessage(), e.getClass());
        return R.error(BizCodeEnume.NOT_WARE_STOCK.getCodeException(), BizCodeEnume.NOT_WARE_STOCK.getMessageException());
    }

    @ExceptionHandler(value = RuntimeException.class)
    public R RuntimeException(RuntimeException e) {
        log.error("异常信息：{}，异常类型：{}", e.getMessage(), e.getClass());
        return R.error(10000, e.getMessage() + ".");
    }

}
